//扁平化对象
function objectFlat(obj = {}) {
    var res = {};
    //所有层级的属性最终都去到第一层
    function flat(item, preKey = "") {
        Object.entries(item).forEach(([key, val]) => {
            var newKey = preKey ? `${preKey}.${key}` : key;
            if (val && (typeof val == "object") && val !== null) {
                flat(val, newKey);
            } else {
                res[newKey] = val;
            }
        });
    }
    flat(obj, '');
    return res;
}

var source = { a: { b: { c: 1, d: 2 }, e: 3 }, f: { g: 2 } };
console.log(objectFlat(source));